package study.method.base;

/**
 * @author Administrator
 * @date 2020/12/12
 */
public class Person {
    //属性私有
    private String name;
    private int age;
    private String sex;

    //Get/Set方法(ALT+INSERT快捷键)
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    //对数据做安全校验,当age<=0或age>120时，返回报错
    public void setAge(int age) {
        if (age <= 0 || age > 120){
            System.out.println("请录入1-120内的数字");
        }else{
            this.age = age;
        }
    }

    public String getSex() {
        return sex;
    }

    //对数据做映射,一般后端存储男女为0,1,但传输给前端时又不能按此展示,此时可以通过set方法进行展示
    public void setSex(String sex) {
        if ("0".equals(sex)){
            this.sex = "男";
        }else if("1".equals(sex)){
            this.sex = "女";
        }else{
            this.sex = "未知的性别";
        }
    }

    public void print(){
        System.out.println("Person");
    }
}
